package com.hy.main.demo.io;

import org.junit.Test;

import java.io.*;
import java.util.Arrays;
import java.util.Comparator;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @Author yang DongYong
 * @Date 2022/4/27 - 04 - 27 - 2:49
 * @Description: com.hy.main.demo.file
 * @version: 1.0
 */
public class OutPutStreamWrites {

    @Test
    public void outPutStreamWrites() throws IOException {
        String path = "e:\\yyyy.TXT";
        String charSet = "GBK";
        // 字节输出流转换为字符输出流并设置GBK编码方式
        BufferedWriter bufferedWriter = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(path), charSet));
        List<String> date = Arrays.asList("周三", "周一", "周二");
        date.stream().sorted(Comparator.reverseOrder()).collect(Collectors.toList()).forEach(e -> {
            try {
                bufferedWriter.write(e);
                bufferedWriter.newLine();
            } catch (IOException ioException) {
                ioException.printStackTrace();
            }
        });
        bufferedWriter.close();
    }
}
